package com.hjh.webdemo.controller;

import com.hjh.webdemo.Service.UserService;
import com.hjh.webdemo.entity.User;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
    public User gerUser(Integer id){
        User user = userService.getUser(id);
        return user;
    }

    @GetMapping(value = "/users")
    public List<User> findAllUsers(){
        List<User> list = userService.findAllUsers();
        return list;
    }

    @GetMapping(value = "/user/{id}")
    public User getUser(@PathVariable("id") Integer id){
        User user = userService.getUser(id);
        return user;
    }

    @PostMapping(value = "/user")
    public void addUser(User user){
        userService.addUser(user);
    }

    @PutMapping(value = "/user")
    public void updateUser(User user){
        userService.updateUser(user);
    }

    @DeleteMapping(value = "/user/{id}")
    public void deleteUser(@PathVariable("id") Integer id){
        userService.deleteUser(id);
    }
}
